<template>
	<div class="role">
		<div class="container">
			<STform :ref-obj.sync="searchInfo.ref" :data="searchInfo.data"  :field-list="searchInfo.searchFormList" 
				:listTypeInfo="dictList" :inline="true" :rules="searchInfo.rules" label-width=" " >
				<template slot="form-btn">
						<el-button type="primary" @click="doSearch">查询</el-button>
						<el-button @click="searchInfo.ref && searchInfo.ref.resetFields()">重置</el-button>
				</template>
			</STform>
			<STtable size="mini" :data.sync="tableData" @doRefresh="fetchData" :field-list="tables" :pagination="pagination" :loading="loading" @handleClick="handleClick" @handleEvent="handleEvent">
				<template slot="col-type" slot-scope="scope">{{(dicts.sysLogType[scope.row.type])? dicts.sysLogType[scope.row.type]:"其他"}}</template>
			</STtable>
		</div>
	</div>
</template>

<script>
	import STtable from '@/components/common/STtable'
	import STform from '@/components/common/STform'
	import {dblog} from '@/api/admin.js'
	import consts from './consts.js'
	import {mapState} from 'vuex' //本地取信息
	export default {
		components: {STtable,STform},
		data() {
			return {
				searchInfo: {
					ref: null,
					data: { //搜索展示的字段
						query: '',
						type: '',
						table: '',
						stime: [],
					},
					rules: {},
					searchFormList: consts.searchFormList // 查询列表表单列 数据
				},
				multipleSelection: [], //选中数据
				sysPageForm: { //搜索实际请求的字段
				},
				loading: true,
				tableData: [], //列表数据
				tables:consts.tables,
				pagination: { // 分页数据
					pageNum: 1, // 当前页
					pageSize: 20, // 每页条数
					total: 0, //合计条数
					sorts: {id: 'DESC'},//排序信息
					pageSizes: [5, 10, 20, 50, 100], // 分页数量列表
					sizeChange: (val) => {
						this.onSizeChange(val)
					},
					currentChange: (pageNum) => {
						this.onCurrentChange(pageNum)
					},
					sortsChange:(sorts) => {
						this.onSortsChange(sorts);
					},
				},
			}
		},
		async created() {
			await this.fetchData();
			const orm = '\\model\\main\\sys\\Syslog';
			await this.$store.dispatch("dictSrv/sysTable", {orm:orm});
			this.loading = false;
		},
		computed: {
			dictList() {
				return this.$store.getters["dictSrv/list"];
			},
			...mapState({
        dicts: (state) => {
          return state.dictSrv.data;
        }
      })
		},
		methods: {
			doSearch() {
				const data = this.searchInfo.data;
				Object.assign(this.sysPageForm, data);
				this.fetchData(this.sysPageForm);
			},
			onSortsChange(sorts) {
				this.pagination.sorts = sorts;
				this.fetchData(this.sysPageForm);
			},
			onSizeChange(pageSize) {
				this.pagination.pageSize = pageSize
				this.fetchData(this.sysPageForm)
			},
			onCurrentChange(pageNum) {
				this.pagination.pageNum = pageNum
				this.fetchData(this.sysPageForm)
			},
			async fetchData(params) {
				this.loading = false;
				const { pageNum, pageSize, sorts } = this.pagination;
				console.log({start:(pageNum - 1)*pageSize, limit:pageSize, ...params}, params);
				const ojson = await dblog({start:(pageNum - 1)*pageSize, limit:pageSize, sorts:sorts, ...params});
				if (ojson) {
					this.tableData = ojson.dataset;
					this.pagination.total = ojson.total;
				}
				this.loading = false;
			},
			handleClick() {
			},
			handleEvent(type, data) {
				switch (type) {
					case 'tableCheck':
						this.multipleSelection = []
						for (const index in data) {
							this.multipleSelection.push(data[index].styleId);
						}
						break
				}
			}
		}
	}
</script>

<style >
</style>
